var ds_distributer_all = new Ext.data.Store({
	proxy:new Ext.data.HttpProxy({url:'manuscriptWork_forDistributer_list.action',method:'POST'}),
	baseParams : {type : 0},
	reader:new Ext.data.JsonReader({
		root:'manuscriptWorks',
		totalProperty:'totalCount'},
		[
			{name:'manuscriptId',mapping:'manuscriptId',type:'long'},
			{name:'manuscriptWorkId',mapping:'manuscriptWorkId',type:'long'},
			{name:'type',mapping:'type',type:'long'},
			{name:'status',mapping:'status',type:'long'},
			{name:'confirmerId',mapping:'confirmerId',type:'long'},
			{name:'description',mapping:'description',type:'string'},
			{name:'title',mapping:'manuscript.title',type:'string'},
			{name:'plannedConsummationTime',mapping:'manuscript.plannedConsummationTime',type:'long'},
			{name : 'urgence',mapping : 'manuscript.urgence',type : 'short'}, 
			{name : 'securityClassification',mapping : 'manuscript.securityClassification',type : 'short'},
			{name:'operation',type:'string'}
		]
	)
});

var tip="6为最高级别";
function totime(value, metadata, record) {
	return new Date(value).format('Y-m-d H:i');
}
function bankTime(value, metadata, record) {
	return new Date(value).format('Y-m-d');
}
function tourgence(value) {
	switch (value) {
		case 0 :
			return "普通";
			break;
		case 5 :
			return "紧急";
			break;
		case 10 :
			return "特急";
			break;
	}
}

function tosecurityClassification(value) {
	switch (value) {
		case 1 :
			return "普通";
			break;
		case 2 :
			return "秘密";
			break;
		case 3 :
			return "机密";
			break;
		case 5 :
			return "绝密";
			break;
	}
}

function toSecurityGrade(value) {
	switch (value) {
		case 1 :
			return "普通";
			break;
		case 2 :
			return "秘密";
			break;
		case 3 :
			return "机密";
			break;
		case 5 :
			return "绝密";
			break;
	}
}

function tolanguage(value) {
	switch (value) {
		case 1 :
			return "汉语";
			break;
		case 2 :
			return "藏语";
			break;
	}
}

function totargetLanguage(value) {
	switch (value) {
		case 1 :
			return "汉语";
			break;
		case 2 :
			return "藏语";
			break;
	}
}

function totexttype(value) {
	switch (value) {
		case 0 :
			return "纸质稿件";
			break;
		case 0x0100 :
			return "电子稿件";
			break;
	}
}

function totype(value) {
	if(value=="DW"){
		return "党委";
	}else if(value=="RD"){
		return "人大";
	}else if(value=="ZF"){
		return "政府";
	}else if(value=="ZX"){
		return "政协";
	}else if(value=="QT"){
		return "其他";
	}else{
		return value;
	}
}

var urgence;
var securityClassification;
var language;
var targetLanguage;
var contributeTime;
var plannedConsummationTime;
var type;
var texttype;
function formchange(respText) {
	urgence = tourgence(respText.manuscript.urgence);
	securityClassification = tosecurityClassification(respText.manuscript.securityClassification);
	language = tolanguage(respText.manuscript.language);
	targetLanguage = totargetLanguage(respText.manuscript.targetLanguage);
	contributeTime = totime(respText.manuscript.contributeTime, "", "");
	plannedConsummationTime = totime(
			respText.manuscript.plannedConsummationTime, "", "");
	texttype = totexttype(respText.manuscript.type);
	type = totype(respText.contributeCompany.type);
}

var re;
function tomark(value, metadata, record) {
    var title = '&nbsp;密级&nbsp;&nbsp;&nbsp;&nbsp;紧急程度&nbsp;';
    var tip;
    var s1 = "&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;";
    var s2 = "&nbsp;秘密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s3 = "&nbsp;机密&nbsp;&nbsp;&nbsp;&nbsp;";
    var s5 = "&nbsp;绝密&nbsp;&nbsp;&nbsp;&nbsp;";
    var u0 = "&nbsp;&nbsp;&nbsp;普通&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    var u5 = "&nbsp;&nbsp;&nbsp;紧急&nbsp;&nbsp;&nbsp;&nbsp;";
    var u10 = "&nbsp;&nbsp;&nbsp;特急";
    var c0 = "&nbsp<img src='images/clock_blue.gif'  />&nbsp";// 普通urgence
    var c5 = "&nbsp<img src='images/clock_green.gif' />&nbsp";// 紧急
    var c10 = "&nbsp<img src='images/clock_red.gif' />&nbsp";// 特急
    var l1 = "&nbsp<img src='images/lock_blue.gif'  />&nbsp";// 普通securityClassification
    var l2 = "&nbsp<img src='images/lock_gold.gif'/>&nbsp"; // 秘密
    var l3 = "&nbsp<img src='images/lock_green.gif' />&nbsp";// 机密
    var l5 = "&nbsp<img src='images/lock_red.gif'  />&nbsp";// 绝密
    switch (record.data.securityClassification) {
        case 1:
            switch (record.data.urgence) {
                case 0:
                	re = l1 + c0;
                    tip = s1 + u0;
                    break;
                case 5:
                	re = l1 + c5 ;
                    tip = s1 + u5;
                    break;
                case 10:
                	re = l1 + c10;
                    tip = s1 + u10;
                    break;
            }
            break;
        case 2:
            switch (record.data.urgence) {
                case 0:
                	re = l2 + c0;
                    tip = s2 + u0;
                    break;
                case 5:
                	re = l2 + c5;
                    tip = s2 + u5;
                    break;
                case 10:
                	re = l2 + c10;
                    tip = s2 + u10;
                    break;
            }
            break;
        case 3:
            switch (record.data.urgence) {
	            case 0:
	            	re = l3 + c0;
	                tip = s3 + u0;
	                break;
	            case 5:
	            	re = l3 + c5;
	                tip = s3 + u5;
	                break;
	            case 10:
	            	re = l3 + c10;
	                tip = s3 + u10;
	                break;
            }
            
            break;
        case 5:
            switch (record.data.urgence) {
	            case 0:
	            	re = l5 + c0;
	                tip = s5 + u0;
	                break;
	            case 5:
	            	re = l5 + c5;
	                tip = s5 + u5;
	                break;
	            case 10:
	            	re = l5 + c10;
	                tip = s5 + u10;
	                break;
	            }
            break;
    }
    metadata.attr = 'ext:qtitle="' + title + '"' + ' ext:qtip="' + tip + '"';
    return re;
}
function changeRemark(respText){
    return "<div align=\"center\"><a href='javascript:void(0)'  onclick=javascript:showRemark('" + respText.manuscript.manuscriptId + "')>备注详情</a></div>";
}

function changeWorkRemark(needParam1,needParam2){
    return "<div align=\"center\"><a href='javascript:void(0)'  onclick=javascript:showWorkRemark('" + needParam1 + "','"+needParam2+"')>备注详情</a></div>";
}

window.showWorkRemark = function(needParam1,needParam2){
    Ext.Ajax.request({
        url: 'manuscriptWork_view.action',
        method: 'post',
        params: {
            manuscriptId: needParam1,
            manuscriptWorkId: needParam2
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                var window_remark = new Ext.Window({
                    title: '备注详情',
                    closable: false,
                    width: 600,
                    resizable: false,
                    height: 400,
                    iconCls: 'manuscript',
                    modal: true,
                    constrain: true,
                    closeAction: 'close',
                    layout: 'fit',
                    items: [{
                        xtype: 'htmleditor',
                        enableAlignments: false,
                        enableColors: false,
                        enableFont: false,
                        enableFontSize: false,
                        enableFormat: false,
                        enableLinks: false,
                        enableLists: false,
                        enableSourceEdit: false,
                        readOnly: true,
                        value: respText.manuscriptWork.remark
                    }],
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            window_remark.close();
                        }
                    }]
                
                
                }).show();
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    })
};

window.showRemark = function(v){
    Ext.Ajax.request({
        url: 'manuscript_view.action',
        method: 'post',
        params: {
            manuscriptId: v
        },
        success: function(resp, opts){
            var respText = Ext.util.JSON.decode(resp.responseText);
            if (respText.success) {
                var window_remark = new Ext.Window({
                    title: '备注详情',
                    closable: false,
                    width: 600,
                    resizable: false,
                    height: 400,
                    iconCls: 'manuscript',
                    modal: true,
                    constrain: true,
                    closeAction: 'close',
                    layout: 'fit',
                    items: [{
                        xtype: 'htmleditor',
                        enableAlignments: false,
                        enableColors: false,
                        enableFont: false,
                        enableFontSize: false,
                        enableFormat: false,
                        enableLinks: false,
                        enableLists: false,
                        enableSourceEdit: false,
                        readOnly: true,
                        value: respText.manuscript.remark
                    }],
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            window_remark.close();
                        }
                    }]
                
                
                }).show();
            }
        },
        failure: function(){
            Ext.Msg.show({
                title: '错误提示',
                msg: '查看失败!',
                buttons: Ext.Msg.OK,
                icon: Ext.Msg.ERROR,
                width: 200
            });
        }
    })
};

addColor = function(param) {
	if (param == 256) {
		return 'green';
	} else if (param == 512) {
		return 'blue';
	} else if (param == 768) {
		return 'red';
	} else {
		return 'gray';
	}
}

isDisables = function(param) {
	if ((param & 0x1000) == 0x1000) {
		return "disabled='disabled'";
	} else {
		return "enabled='enabled'";
	}
}


window.confirmWork = function(param){
	Ext.Ajax.request({
				url : 'manuscriptWork_confirm.action',
				method : 'post',
				params : {
					manuscriptWorkId : param
				},
				success : function(resp, opts) {
					var respText = Ext.util.JSON.decode(resp.responseText);
					if(respText.success){
						Ext.Msg.show({
								title : '提示信息',
								msg : '确认成功!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.INFO,
								width : 200
							});
							ds_distributer_all.load({
			     	  	    				 params:{
			     	  	    				 	start:0,
			     	  	    				 	limit:20
			     	  	    				 }
			     	  	    			});
					}else{
						Ext.Msg.show({
								title : '错误提示',
								msg : '确认失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
					}
				},
				failure : function() {
					Ext.Msg.show({
								title : '错误提示',
								msg : '确认失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
				}
	})
}

listWorker = function(value){
	var temp = "";
	for (var i = 0; i < value.length; i++) {
		temp = temp + value[i].manuscriptWorkerName + "; ";
	}
	return temp;
}

window.showManuscriptWorkView = function(needParam1,needParam2) {
	Ext.Ajax.request({
		url : 'manuscriptWork_view.action',
		methord : 'post',
		params : {
			manuscriptId : needParam1,
			manuscriptWorkId : needParam2
			
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			var manuscriptWork = respText.manuscriptWork;

			var type = '';
			var status = '';

			if (manuscriptWork.type == 1) {
				type = '翻译';
			} else if (manuscriptWork.type == 2) {
				type = '校审';
			} else if (manuscriptWork.type == 3) {
				type = '校对';
			} else {
				type = '审核';
			}

			if (manuscriptWork.status == 1) {
				status = '分发完成';
			} else if (manuscriptWork.status == 2) {
				status = '工作进行中';
			} else if (manuscriptWork.status == 3) {
				status = '工作完成';
			}else if (manuscriptWork.status == 4) {
				status = '工作部分完成';
			} else if (manuscriptWork.status == 10) {
				status = '工作被拒绝';
			} else if(manuscriptWork.status == 11) {
				status = '工作被取消';
			}

			if (respText.success) {
			var	manuscriptWorkshow=new Ext.Window({
					title : '稿件工作详情',
					constrain :true,
					width : 600,
					constrain :true,
					resizable : false,
					closable : false,
					autoHeight : true,
					modal : true,
					closeAction : 'hide',
					items : [new Ext.FormPanel({
								labelAlign : 'right',
								labelWidth : 100,
								frame:true,
								defaults : {
									itemCls : 'form_text'
								},
								defaultType : 'textfield',
								items : [{
											fieldLabel : '稿件标题',
											value : respText.manuscript.title,
											readOnly : true,
											itemCls : 'form_long unedit',
											anchor : '93%'
											},{
											fieldLabel : '稿件工作类型',
											value : type,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '状态',
											value : status,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '工作开始时间',
											value : formatTime(manuscriptWork.startTime,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '要求完成时间',
											value : formatTime(manuscriptWork.plannedFinishedTime,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '分发人',
											value : manuscriptWork.assignerName,
											readOnly : true,
											itemCls : 'form_text unedit'
										},{
											fieldLabel : '统稿人姓名',
											value : manuscriptWork.principalName,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '创建时间',
											value : formatTime(manuscriptWork.startTime,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '确认人姓名',
											value : manuscriptWork.confirmerName,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '确认时间',
											value : formatTime(manuscriptWork.confirmedTimestamp,"",""),
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '工作人数',
											value : manuscriptWork.workerNum,
											readOnly : true,
											itemCls : 'form_text unedit'
										}, {
											fieldLabel : '工作人员',
											value : listWorker(manuscriptWork.manuscriptWorkers),
											readOnly : true,
											anchor : '93%',
											itemCls : 'form_long unedit'
										}, {
											xtype : 'textarea',
											fieldLabel : '工作任务描述',
											readOnly : true,
											itemCls : 'form_long clear unedit',
											anchor : '93%',
											value : manuscriptWork.description
										}, {
                            fieldLabel: '备注',
                            xtype: 'panel',
                            width: 425,
                            itemCls: 'clear',
                            html: changeWorkRemark(needParam1,needParam2)
                        }],
										buttons:[{
											text:'关闭',
											handler:function(){
											manuscriptWorkshow.close();
										}
										}]
							})]

				}).show();
			} else {
				Ext.Msg.show({
					title : '错误提示',
					msg : '查看失败!',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
			}
		},
		failure : function() {
			Ext.Msg.show({
						title : '错误提示',
						msg : '查看失败!',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	});
};

var cm_distributer_all = new Ext.grid.ColumnModel([
	new Ext.grid.RowNumberer(),
	{header:'稿件标题',width:300,dataIndex:'title',sortable:true,renderer:function(value, metadata, record)
		{
    	 	return "<a href = 'javascript:void(0)' onclick=javascript:distributer_Manuscript_Show('" + record.data.manuscriptId + "')>" + escapeHTML(value) + "</a>";
		}
	},
	{header:'稿件工作类型',dataIndex:'type',sortable:true,renderer : function(value, metadata, record) {
		if (value == 1) {
			return '翻译';
		} else if (value == 2) {
			return '校审';
		} else if (value == 3) {
			return '校对';
		} else {
			return '审核';
		};
	}},
	{header:'稿件工作状态',dataIndex:'status',sortable:true,renderer : function(value, metadata, record) {
		if (value == 1) {
			return '分发完成';
		} else if (value == 2) {
			return '工作进行中';
		} else if (value == 3) {
			return '工作完成';
		}else if (value == 4) {
			return '工作部分完成';
		}else if (value == 10) {
			return '工作被拒绝';
		} else if (value == 11) {
			return '工作被取消';
		};
	}},
	{header:'计划完成时间',dataIndex:'plannedConsummationTime',sortable:true,renderer: function(value, metadata, record){
//	    return formatTime(value, metadata, record);
		return new Date(value).format('Y-m-d');
    }},
	{
			header : '标识',
			sortable : true,
			renderer : function drawmark(value, metadata, record) {
				return tomark(value, metadata, record);
			}
		},
	{header:"操作",width:200,dataIndex:'operation',renderer:function(value, metadata, record){
		if (record.data.status == 1) {
			return "<a href = 'javascript:void(0)' onclick=javascript:showManuscriptWorkView('"+ record.data.manuscriptId +"','"+ record.data.manuscriptWorkId +"')>查看</a>&nbsp;&nbsp;&nbsp;"+"<a href = 'javascript:void(0)' onclick=javascript:addWorker('"
					+ record.data.manuscriptId
					+ "','" + record.data.manuscriptWorkId + "')>增加 </a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick=javascript:deleteWorker('"
					+ record.data.manuscriptId
					+"','" + record.data.manuscriptWorkId + "')>减少</a>&nbsp;&nbsp;&nbsp;<a href = 'javascript:void(0)' onclick=javascript:cancelManuscriptWork('"
					+ record.data.manuscriptWorkId + "')>取消 </a>&nbsp;<font color='#cccccc'>确认</font>";
		} else if (record.data.status == 2) {
			return "<a href = 'javascript:void(0)' onclick=javascript:showManuscriptWorkView('"+ record.data.manuscriptId +"','"+ record.data.manuscriptWorkId +"')>查看</a>&nbsp;&nbsp;&nbsp;"+"<a href = 'javascript:void(0)' onclick=javascript:addWorker('"
					+ record.data.manuscriptId
					+ "','" + record.data.manuscriptWorkId + "')>增加 </a>&nbsp;&nbsp;<a href='javascript:void(0)' onclick=javascript:deleteWorker('"
					+ record.data.manuscriptId
					+"','" + record.data.manuscriptWorkId+ "')>减少</a>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>取消</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>确认</font>";
		} else if(record.data.status == 3 || record.data.status == 10){
			if(record.data.confirmerId == null){
				return "<a href = 'javascript:void(0)' onclick=javascript:showManuscriptWorkView('"+ record.data.manuscriptId +"','"+ record.data.manuscriptWorkId +"')>查看</a>&nbsp;&nbsp;&nbsp;"+"<font color='#cccccc'>增加</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>减少</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>取消</font>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' onclick=javascript:confirmWork('"
						+record.data.manuscriptWorkId+"')>确认</a>";
			}else{
				return "<a href = 'javascript:void(0)' onclick=javascript:showManuscriptWorkView('"+ record.data.manuscriptId +"','"+ record.data.manuscriptWorkId +"')>查看</a>&nbsp;&nbsp;&nbsp;"+"<font color='#cccccc'>增加</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>减少</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>取消</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>确认</font>";
			}
		}else{
		}
			return "<a href = 'javascript:void(0)' onclick=javascript:showManuscriptWorkView('"+ record.data.manuscriptId +"','"+ record.data.manuscriptWorkId +"')>查看</a>&nbsp;&nbsp;&nbsp;"+"<font color='#cccccc'>增加</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>减少</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>取消</font>&nbsp;&nbsp;&nbsp;<font color='#cccccc'>确认</font>";
		}
	}
]);

var grid_distributer_all = new Ext.grid.GridPanel({
	title : '所有分发 ',
	loadMask : {msg : '数据加载中...'},
	ds:ds_distributer_all,
	store:ds_distributer_all,
	region : 'center',
	autoScroll: true,
	cm:cm_distributer_all,
	autoExpandColumn :6 ,
	bbar : new Ext.PagingToolbar({
		pageSize : 20,
		store : ds_distributer_all,
		displayInfo : true,
		beforePageText:'第',
		afterPageText:'页-共{0}页',
		displayMsg : '显示{0} - {1} 条  共 {2} 条',
		emptyMsg : "没有记录"
	})
});

ds_distributer_all.load({params:{start:0,limit:20}});

window.distributer_Manuscript_Show = function(needParam) {
	Ext.Ajax.request({
				url : 'manuscript_view.action',
				method : 'post',
				params : {
					manuscriptId : needParam
				},
				success : function(resp, opts) {
					var respText = Ext.util.JSON.decode(resp.responseText);
					formchange(respText);
					if (respText.success) {
						var mywindow = new Ext.Window({
							title : '稿件详情',
							width : 600,
							resizable : false,
							constrain: true,
							closable : false,
							autoHeight : true,
							modal : true,
							iconCls:'manuscript',
							closeAction : 'hide',
							items : [new Ext.FormPanel({
						border : false,
						labelAlign : 'right',
						plain : true,
						labelWidth : 100,
						frame : true,
						items : [{
								fieldLabel : '稿件标题',
								xtype : 'textfield',
								readOnly : true,
								value : respText.manuscript.title,
								width : 426,
								itemCls : "unedit"
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '来稿单位',
								readOnly : true,
								value : respText.manuscript.contributeCompany.contributeCompanyName,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '来稿单位类型',
								readOnly : true,
								value : type,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '联系人',
								readOnly : true,
								value : respText.manuscript.contributeCompanyPerson.name,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '稿件编号',
								readOnly : true,
								value : respText.manuscript.manuscriptCode,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '联系人手机',
								readOnly : true,
								value : respText.manuscript.contributeCompanyPerson.mobilePhone,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '联系人邮箱',
								readOnly : true,
								value : respText.manuscript.contributeCompanyPerson.email,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '稿件分类',
								readOnly : true,
								value : respText.manuscript.manuscriptCategory.manuscriptCategoryName,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '紧急程度',
								readOnly : true,
								value : urgence,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '文档类型',
								readOnly : true,
								value : texttype,
								itemCls : 'form_text unedit'
							},  {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '原稿文种',
								readOnly : true,
								value : language,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '密级',
								readOnly : true,
								value : securityClassification,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '目标语言',
								readOnly : true,
								value : targetLanguage,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '字数',
								readOnly : true,
								value : respText.manuscript.wordNum,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '来稿时间',
								readOnly : true,
								value : contributeTime,
								itemCls : 'form_text unedit'
							}, {
								autoHeight : true,
								xtype : 'textfield',
								fieldLabel : '计划完成时间',
								readOnly : true,
								value : plannedConsummationTime,
								itemCls : 'form_text unedit'
							},{
								autoHeight : true,
								xtype : 'textfield',
								itemCls : 'form_text unedit',
								fieldLabel : '创建人姓名',
								value : respText.manuscript.creatorName,
								readOnly : true
							}, {
								autoHeight : true,
								xtype : 'textfield',
								itemCls : 'form_text unedit',
								fieldLabel : '创建时间',
								value : formatTime(respText.manuscript.createdTimestamp,"",""),
								readOnly : true
							},{
								autoHeight : true,
								xtype : 'textfield',
								itemCls : 'form_text unedit',
								fieldLabel : '最后修改人',
								value : respText.manuscript.lastModifierName,
								readOnly : true
							}, {
								autoHeight : true,
								xtype : 'textfield',
								itemCls : 'form_text unedit',
								fieldLabel : '最后修改时间',
								value : formatTime(respText.manuscript.lastModifiedTimestamp,"",""),
								readOnly : true
							}, {
                            fieldLabel: '备注',
                            xtype: 'panel',
                            width: 425,
                            itemCls: 'clear',
                            html: changeRemark(respText)
                        }],
							buttons : [{
					     		text : '关闭',
					     		handler : function() {
									mywindow.hide();
								}
					     	}]
					})]

						}).show();
					} else {
						Ext.Msg.show({
								title : '错误提示',
								msg : '查看详情失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
					}
				},
				failure : function() {
					Ext.Msg.show({
								title : '错误提示',
								msg : '修改失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
				}
	});
};

var manuscriptWork_tabPanel = new Ext.TabPanel({
	id : 'centerTabPanel',
	region : 'center',
	deferredRender : true,
	enableTabScroll : true,
	autoWidth: true,
	autoScroll: true,
	activeTab : 0, // first tab initially active
	defaults : {
		autoScroll : true,
		closable : false
	},
	items : [grid_distributer_all]
});

var toptip = "";
workShowadd = function(metadata,userId){
	Ext.Ajax.request({
		url : 'worksByPerson_list.action',
		method : 'post',
		async : false, 
		params : {
			userId : userId
		},
		success : function(resp, opts) {
			toptip = "";
			var respText = Ext.util.JSON.decode(resp.responseText);
			if(respText.success){
				manuscriptWorksByPerson = respText.manuscriptWorksByPerson;
				if(manuscriptWorksByPerson.length != 0){
					for (var i = 0; i < manuscriptWorksByPerson.length; i++) {
						if(manuscriptWorksByPerson[i].manuscript.title.length >10){
							toptip = toptip + escapeHTML(manuscriptWorksByPerson[i].manuscript.title.substring(0,10)) + "..." + "</br>";
						}else{
							toptip = toptip + escapeHTML(manuscriptWorksByPerson[i].manuscript.title) + "</br>";
						}
					}
				}
			}
		}
	});
	metadata.attr = ' ext:qtip="' + toptip + '"';
}

window.addWorker = function(needParam1,needParam2) {
	if(Ext.get('win_add_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}
	if(Ext.get('win_delete_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}
	
	Ext.Ajax.request({
		url : 'manuscriptWork_view.action',
		method : 'post',
		params : {
			manuscriptId : needParam1,
			manuscriptWorkId : needParam2
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			if (respText.success) {
				formchange(respText);
				var ds_add_disrtibuter = new Ext.data.Store({
					proxy : new Ext.data.MemoryProxy(respText),
					reader : new Ext.data.JsonReader({
								root : 'usersForDistribute'
							}, [{name : 'userId',mapping : 'userId',type : 'long'},
								{name : 'userName',mapping : 'userName',type : 'string'},
								{name : 'status',mapping : 'status',type : 'long'},
								{name : 'ability',mapping : 'ability',type : 'long'},
								{name : 'status',mapping : 'status',type : 'long'},
								{name : 'securityGrade',mapping : 'securityGrade',type : 'long'}]
						)
				});
				var sm_user=new Ext.grid.CheckboxSelectionModel();
				var cm_translate = new Ext.grid.ColumnModel([
					new Ext.grid.RowNumberer(),
					{header:'稿件工作人员',dataIndex:'userName',renderer:function(value, metadata, record)
						{
							workShowadd(metadata,record.data.userId);
							return "<input type='checkbox' name='manuscriptWorkersId' value='"+record.data.userId+"'"+isDisables(record.data.status)+">  <font color='"+addColor(record.data.status)+"'>"+escapeHTML(record.data.userName)+"</font></input>";
						}
					},
					
					{header:'能力级别',dataIndex:'ability',width:150,sortable:true},
					{header:'涉密级别',dataIndex:'securityGrade',width:150,sortable:true,renderer: function change(value, metadata, record){
					        return tosecurityClassification(value, metadata, record);
					    }
					}
				]);
				
				var grid_disrtibuter = new Ext.grid.GridPanel({
					loadMask : {
						msg : '数据加载中...'
					},
					ds : ds_add_disrtibuter,
					store : ds_add_disrtibuter,
					region : 'form_distributer',
					autoScroll : true,
					cm : cm_translate,
					autoExpandColumn : 1,
					height : 385
				});
				ds_add_disrtibuter.load({
						params : {
							start : 0,
							limit : 20
						}
				});
				
				var form_distributer = new Ext.form.FormPanel({
					resizable : false,
					id : 'form_distributer',
					autoHeight : true,
					autoWidth : true,
					plain : true,
					modal : true,
					labelAlign : 'right',
					frame : true,
					items : [grid_disrtibuter],
					buttons : [{
						text : '增加',
						type : 'submit',
						handler : function() {
							form_distributer.form.doAction('submit', {
								url : 'manuscriptWork_add.action',
								method : 'post',
								params : {
									manuscriptWorkId : needParam2
								},
								success : function(form, action) {
									if (action.result.success) {
										Ext.Msg.show({
													title : '操作提示',
													msg : '增加成功!',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.INFO,
													width : 200
												});
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
										manuscriptWork_tabPanel.setActiveTab(0);
										ds_add_disrtibuter.reload();
									} else {
										Ext.Msg.show({
													title : '错误提示',
													msg : action.result.errorMessage,
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.ERROR,
													width : 200
												});
									}
								},
								failure : function(from, action) {
									Ext.Msg.show({
												title : '错误提示',
												msg : '增加失败',
												buttons : Ext.Msg.OK,
												icon : Ext.Msg.ERROR,
												width : 200
											});
								}
							});
						}
					},{
					     		text : '关闭',
					     		handler : function() {
									manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
									manuscriptWork_tabPanel.setActiveTab(0);
								}
					     	}]
				});
				var win_add_work ={
						title : '增加稿件工作人员',
						autoWidth : true,
						autoHeight:true,
						closable : true,
						autoScroll : true,
						modal : true,
						id : 'win_add_work',
						items : [form_distributer]
					};
			manuscriptWork_tabPanel.add(win_add_work);
			manuscriptWork_tabPanel.setActiveTab(1);
		} else {
			Ext.Msg.show({
						title : '错误提示',
						msg : respText.erroeMessage,
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	},
	failure : function() {
		Ext.Msg.show({
					title : '错误提示',
					msg : '加载失败!',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
	}
});
};

window.deleteWorker = function(needParam1,needParam2) {
	if(Ext.get('win_add_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}
	if(Ext.get('win_delete_work')!= null){
		manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
		manuscriptWork_tabPanel.setActiveTab(0);
	}
	
	
	
	Ext.Ajax.request({
		url : 'manuscriptWork_view.action',
		method : 'post',
		params : {
			manuscriptId : needParam1,
			manuscriptWorkId : needParam2
		},
		success : function(resp, opts) {
			var respText = Ext.util.JSON.decode(resp.responseText);
			var manuscriptWorkers = respText.manuscriptWorkers;
			
			if(manuscriptWorkers.length == 0)
			{
				Ext.Msg.show({
                    title: '信息',
                    msg: '无可供减少的工作人员！',
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.INFO,
                    width: 200
                });
				return;
			}
			if (respText.success) {
				formchange(respText);
				var ds_delete_disrtibuter = new Ext.data.Store({
					proxy : new Ext.data.MemoryProxy(respText),
					reader : new Ext.data.JsonReader({
								root : 'manuscriptWorkers'
							}, [{name : 'manuscriptWorkerId',mapping : 'manuscriptWorkerId',type : 'long'},
								{name : 'manuscriptWorkerName',mapping : 'manuscriptWorkerName',type : 'string'},
								{name : 'status',mapping : 'status',type : 'long'}]
						)
				});
				var sm_user=new Ext.grid.CheckboxSelectionModel();
				var cm_translate = new Ext.grid.ColumnModel([
					new Ext.grid.RowNumberer(),
					{header:'稿件工作人员',dataIndex:'userName',renderer:function(value, metadata, record)
						{
							workShowadd(metadata,record.data.manuscriptWorkerId);
							return "<input type='checkbox' name='userIds' value='"+record.data.manuscriptWorkerId+"'>"+escapeHTML(record.data.manuscriptWorkerName)+"</input>";
						}
					}
					
					
				]);
				
				var grid_disrtibuter = new Ext.grid.GridPanel({
					loadMask : {
						msg : '数据加载中...'
					},
					ds : ds_delete_disrtibuter,
					store : ds_delete_disrtibuter,
					region : 'form_distributer',
					autoScroll : true,
					cm : cm_translate,
					autoExpandColumn : 1,
					height : 385
				});
				ds_delete_disrtibuter.load({
						params : {
							start : 0,
							limit : 20
						}
				});
				var form_distributer = new Ext.form.FormPanel({
					resizable : false,
					id : 'form_distributer',
					autoHeight : true,
					plain : true,
					modal : true,
					labelAlign : 'right',
					frame : true,
					autoWidth : true,
					items : [grid_disrtibuter],
					buttons : [{
						text : '减少',
						type : 'submit',
						handler : function() {
							form_distributer.form.doAction('submit', {
								url : 'manuscriptWork_delete.action',
								method : 'post',
								params : {
									manuscriptWorkId : needParam2
								},
								success : function(form, action) {
									if (action.result.success) {
										Ext.Msg.show({
													title : '操作提示',
													msg : '减少成功!',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.INFO,
													width : 200
												});
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_add_work'));
										manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
										manuscriptWork_tabPanel.setActiveTab(0);
										ds_delete_disrtibuter.reload();
									} else {
										Ext.Msg.show({
													title : '错误提示',
													msg : '减少失败',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.ERROR,
													width : 200
												});
									}
								},
								failure : function(from, action) {
									Ext.Msg.show({
												title : '错误提示',
												msg : '减少失败',
												buttons : Ext.Msg.OK,
												icon : Ext.Msg.ERROR,
												width : 200
											});
								}
							});
						}
					},{
					     		text : '关闭',
					     		handler : function() {
									manuscriptWork_tabPanel.remove(Ext.getCmp('win_delete_work'));
									manuscriptWork_tabPanel.setActiveTab(0);
								}
					     	}]
				});
				var win_delete_work ={
						title : '减少稿件工作人员',
						autoWidth : true,
						autoHeight:true,
						closable : true,
						autoScroll : true,
						modal : true,
						id : 'win_delete_work',
						items : [form_distributer]
					};
			manuscriptWork_tabPanel.add(win_delete_work);
			manuscriptWork_tabPanel.setActiveTab(1);
		} else {
			Ext.Msg.show({
						title : '错误提示',
						msg : respText.erroeMessage,
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR,
						width : 200
					});
		}
	},
	failure : function() {
		Ext.Msg.show({
					title : '错误提示',
					msg : '加载失败!',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR,
					width : 200
				});
	}
});
};

//取消工作
window.cancelManuscriptWork = function(needParam) {
	Ext.Msg.confirm('取消确认', '你确定取消?', function(btn) {
		if (btn == 'yes') {
			Ext.Ajax.request({
				url : "manuscriptWork_cancel.action",
				method : 'post',
				params : {
					manuscriptWorkId: needParam
				},
				success : function(resp, opts) {
					//alert(needParam);
					var respText = Ext.util.JSON.decode(resp.responseText);
					if (respText.success) {
						if(respText.msg == 'wrong')
						{
							Ext.Msg.show({
								title : '错误提示',
								msg : '该取消出现错误!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
						}
						else if(respText.msg == 'ok')
						{  
							   Ext.Msg.show({ 
								title : '正确提示',
								msg : '取消成功!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.INFO,
								width : 200
							      });
							   ds_distributer_all.load({
			     	  	    				 params:{
			     	  	    				 	start:0,
			     	  	    				 	limit:20
			     	  	    				 }
			     	  	    			});
						}
					} else {
						Ext.Msg.show({ 
								title : '正确提示',
								msg : '取消失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.INFO,
								width : 200
							      });
						ds_distributer_all.load({
			     	  	    				 params:{
			     	  	    				 	start:0,
			     	  	    				 	limit:20
			     	  	    				 }
			     	  	    			});
					}
				},
				failure : function() {
					Ext.Msg.show({
								title : '错误提示',
								msg : '修改失败!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR,
								width : 200
							});
				}
			});
		}
	});
};


//时间格式转换
function formatTime(value, metadata, record){
	if(null==value){
		return null;
	}else{
		return new Date(value).format('Y-m-d H:i');
	}
}

var l_distributer_all = {
	id : 'distributer-work',
	border : false,
	layout : 'border',
	items : [manuscriptWork_tabPanel]
};

Ext.getCmp('content-panel').add(l_distributer_all);
Ext.getCmp('content-panel').layout.setActiveItem('distributer-work');
Ext.getCmp('content-panel').uxmodules="undefined";